/*
 * @Author: QIWEIJIE 625132960@qq.com
 * @Date: 2022-10-14 11:44:55
 * @LastEditors: QIWEIJIE 625132960@qq.com
 * @LastEditTime: 2022-10-18 16:01:05
 * @FilePath: \qj_box_activity\src\utils\index.ts
 * @Description: 公用方法封装
 */
/** 倒计时函数 */
export function sleep(time: number) {
    return new Promise<void>((resolve) => {
        setTimeout(() => {
            resolve();
        }, time);
    });
}
/** 是否为微信浏览器 */
export function isWeChat() {
    const ua = window.navigator.userAgent.toLowerCase();
    const match = ua.match(/MicroMessenger/i);
    if (match === null) {
        return false;
    }
    if (match.includes('micromessenger')) {
        return true;
    }
    return false;
}
/** 是否为qq浏览器 */
export function isQQ() {
    const ua = window.navigator.userAgent.toLowerCase();
    const match = ua.match(/QQ/i);
    if (match === null) {
        return false;
    }
    if (match.includes('qq')) {
        return true;
    }
    return false;
}
/** 获取浏览器传参 */
export function getQueryString(name: string) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    };
    return null;
}
/** 判断手机系统 */
export function isAppSystem() {
    const u = navigator.userAgent;
    const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isAndroid) {
        return 'android'
    }
    if (isIOS) {
        return 'ios'
    }
}
/** 时间汉化 */
export function convertChineseDate(dateStr: string) {
    let time: string | string[] = dateStr.replace(/-/g, ':').replace(' ', ':')
    time = time.split(':');
    return time[0] + '年' + time[1] + '月' + time[2] + '日 ' + time[3] + ':' + time[4]
}
